  //选择审批级数时的变化
    jQuery('#auditorNumber').change(function(){
    	var n=jQuery(this).val();
    	jQuery("input[name*='ai']").each(function(){
    		var index=jQuery(this).prop('id').substr(-1);
    		var parent=jQuery(this).parent().parent();
    		if(index>n) 
    			parent.addClass('hide');
    		else
    			parent.removeClass('hide');
    	});
    });
    // 提交审批
    jQuery(".app-btn-submit").on('click', function () {
    	var num = jQuery("#auditorNumber").val();
    	var unitName = jQuery("#unitName").val();
    	
		for(var i=1;i<=num;i++){
			var val= jQuery("#ai"+i).val();
			if(!val){
				message('审批人没有指定！');
				return;
			}
		}

		if(manageCode==''){
			message('管理代码没有填入,请在售后服务单上填入！');
			return;
		}
		
        $.springLemonDialog({
            content: '确认提交审批？',// 确认文本
            clickButton: function (sender, modal, index) {// 按钮事件处理
                // index:0 确认 1：取消
                // sender:事件源 如按钮，sender.html()可得到按钮文字如：取消
                if (index == 0) {
                    if(jQuery("#form-audit-submit") && !jQuery("#form-audit-submit").Validform({tiptype:3, showAllError:true}).check(false)){
                        return;
                    };
                    //提交审批前先保存送审信息
                    var tab3Id = $("#tab3Id").val();
            		var dutyBlongThree=$('input:radio[name="dutyBlongThree"]:checked').val();
            		var outsourcing=$('input:radio[name="outsourcing"]:checked').val();
            		var selfMake=$('input:radio[name="selfMake"]:checked').val();
            		var d= 
            		{
            				"regulationCode":$("#regulationCode").val(),"deliveryDate":$("#deliveryDate").val(),
            				"outCode":$("#outCode").val(),"sendDate":$("#sendDateThree").val(),
            				"dutyBlong":dutyBlongThree,"outsourcing":outsourcing,
            				"selfMake":selfMake,"payReason":$("#payReason").val(),
            				"summation":$("#summation").val(),"financePerson":$("#financePerson").val(),
            				"dealDate":$("#dealDate").val(),"sendWay":$("#sendWay").val(),
            				"sendPlace":$("#sendPlace").val(),"receiveUnit":$("#receiveUnit").val(),
            				"contactPerson":$("#contactPerson").val(),"contactPhone":$("#contactPhone").val(),
            				"postNumber":$("#postNumber").val(),"dealSuperior":$("#dealSuperior").val()
            		}
            		var url = window.rootPath + '/api/afterSaleTicketAdvices/' + tab3Id;
            		jQuery.ajax({
            			url : encodeURI(url),
            			type : 'patch',
            			data : JSON.stringify(d),
            			dataType : 'json',
            			contentType : 'application/json;charset=utf-8',
            			success : function() {
            				var operateType = "售后服务单办理";
            				var content = "三包服务单【"+jQuery("#unitName").val()+"】提交审批";
            				addOperateLog(operateType,content);
            				var url = window.rootPath + "/ui/afterSaleInHouse/audit/" + jQuery('#ticketId').val()+"?unitName="+unitName;
                            jQuery.post(encodeURI(url), 
                            		{
                            			"auditorNumber":jQuery("#auditorNumber").val(),
                            			"auditor1":jQuery("#auditor1").val(),
                            			"auditor2":jQuery("#auditor2").val(),
                            			"auditor3":jQuery("#auditor3").val(),
                            			"auditor4":jQuery("#auditor4").val(),
                            			"auditor5":jQuery("#auditor5").val(),
                            			"auditor6":jQuery("#auditor6").val(),
                            			"auditor7":jQuery("#auditor7").val(),
                            			"auditor8":jQuery("#auditor8").val()
                            			               	
                            		}, function (data) {

                                    if (data.code == 0) {
                                        window.location = window.rootPath + "/ui/afterSaleInHouse/";
                                    }
                                }
                            );
            			}

            		});
                    

                }
                $(this).closeDialog(modal);
            }
        });

    });
    
 // 引入客户信息弹窗
    jQuery('.btn-find-auditor').on("click", function () {
    	currentAuditor=jQuery(this).prop('id');
        jQuery("#modal-find-auditor").modal('show');
        jQuery("#modal-find-auditor input[type='radio']").attr('checked',false);
    });
    
    
    
    
    //用户查找弹窗
    var serverUserData = {};
    serverUserTable = jQuery('#table-user').DataTable({
        "serverSide": true,
        "iDisplayLength": 4,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url": window.rootPath + '/ui/user/getpage',
            "data": function (d) {
                return $.extend({}, d, serverUserData);
            }
        },
        columns: [
            {
                // 1序号
                data: null,
                defaultContent: ""
            },
            {// 2姓名
                data: "empLogin.name",
            },
            {// 3性别
                data: 'sex'
            },

            {// 4职务
                data: 'position'
            },
            {// 5销售区域
                data: 'saleArea.superiorArea'
            },
            {//6选择按钮
            	data:null,
            	render:function(){
            		var html="<input type='radio' name='btn-select' class='app-select-user'/>"
            			return html;
            	}
            }
            
        ],
        "drawCallback": function (oSettings) {
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                k++;
            }

            serverUserTable.off('click', 'tr');
            serverUserTable.on('click', 'tr', function (event) {
                event = event || window.event;
                var target = event.target || event.scrElement;
                var data = serverUserTable.row(this).data();

                if (target.className.indexOf('app-select-user') != -1) {
                    onSelectUser(data);
                }
                return;
            });
        }
    });//end of datatable
var selectedUser=null;    
var currentAuditor=null;
var  onSelectUser=function onSelectUser(data){
			selectedUser=data;
    };
    
    //引入用户按钮
    jQuery('#btn-reference').on('click',function(){
        if(selectedUser && currentAuditor){
        	jQuery("#ai"+currentAuditor).val(selectedUser.empLogin.userName);
        	jQuery("#auditor"+currentAuditor).val(selectedUser.id);                	
        }
        	
        selectedUser=null;
        currentAuditor=null;
        jQuery("#modal-find-auditor").modal('hide');
    });
    //查找用户返回按钮
    jQuery('.app-find-user-return').on('click',function(){
        selectedUser=null;
        currentAuditor=null;
    });
    //查询
    jQuery('.app-btn-search').on('click',function(){
        serverUserData.key=jQuery("#search").val();
        serverUserTable.draw();
    });
    //撤销查询
    jQuery('.app-btn-reset').on('click',function(){
        jQuery('#search').val('');
        serverUserData.key='';
        serverUserTable.draw();
    });      
    
    
    
    
    
    
    

